/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header$
 * $Id$
 * $Author$
 * $Date$
 * $Revision$
 */
package com.elancom.framework.component.internal;

import java.util.ArrayList;
import java.util.List;

import com.elancom.framework.component.Component;
import com.elancom.framework.component.Input;
import com.elancom.framework.component.Invocation;
import com.elancom.framework.component.InvocationContext;
import com.elancom.framework.component.InvocationFactory;
import com.elancom.framework.component.Output;
import com.elancom.framework.component.ServiceReceiver;
import com.elancom.framework.component.interceptor.FireEventInterceptor;
import com.elancom.framework.component.interceptor.Interceptor;
import com.elancom.framework.component.interceptor.ValidateInterceptor;

/**
 * @author elancom
 * @date 2012-8-9
 */
public class DefaultInvocationFactory implements InvocationFactory {
	// private static Map<String, Interceptor> interceptors = new HashMap<String, Interceptor>();
	// interceptors.put(fireEventInterceptor.getClass().getName(), fireEventInterceptor);

	private static List<Interceptor> INTERCEPTOR_LIST = new ArrayList<>();

	static {
		ValidateInterceptor validateInterceptor = new ValidateInterceptor();
		FireEventInterceptor fireEventInterceptor = new FireEventInterceptor();

		INTERCEPTOR_LIST.add(validateInterceptor);
		INTERCEPTOR_LIST.add(fireEventInterceptor);
	}

	@Override
	public Invocation factory(ServiceReceiver serviceReceiver, Component component, Input input, Output output) {
		InvocationContext cxt = new InvocationContext(component, input, output);
		DefaultInvocation invocation = new DefaultInvocation(cxt);
		invocation.setServiceReceiver(serviceReceiver);
		invocation.setIterator(INTERCEPTOR_LIST.iterator());
		return invocation;
	}
}
